const colors: Record<string, string> = {
  primary: "#2d8cf0",
  success: "#19be6b",
  info: "#909399",
  warning: "#ff9900",
  danger: "#f03f14",
  default: "#35495E"
};

const logger = {
  getColor(type: string) {
    return colors[type] ?? colors.default;
  },

  print(type = "default", text: any, back = false) {
    if (typeof text === "object") {
      return Array.isArray(text) ? console.table(text) : console.dir(text);
    }
    if (back) {
      return console.log(
        `%c ${text} `,
        `background:${logger.getColor(type)}; padding: 2px; border-radius: 4px; color: #fff;`
      );
    } else {
      return console.log(
        `%c ${text} `,
        `border: 1px solid ${logger.getColor(type)};padding: 2px; border-radius: 4px;color: ${logger.getColor(type)};`
      );
    }
  },

  back(type = "primary", text: string) {
    return this.print(type, text, true);
  },

  pretty(type = "primary", title: string, text: string) {
    if (typeof text === "object") {
      console.group("Console Group", title);
      console.log(
        `%c ${title}`,
        `background:${logger.getColor(type)};border:1px solid ${logger.getColor(type)};padding: 1px; border-radius: 4px; color: #fff;`
      );
      Array.isArray(text) ? console.table(text) : console.dir(text);
      console.groupEnd();
      return;
    }
    return console.log(
      `%c ${title} %c ${text} %c`,
      `background:${logger.getColor(type)};border:1px solid ${logger.getColor(type)};padding: 1px; border-radius: 4px 0 0 4px; color: #fff;`,
      `border:1px solid ${logger.getColor(type)};padding: 1px; border-radius: 0 4px 4px 0; color: ${logger.getColor(type)};`,
      "background:transparent"
    );
  },

  primary(title: string, ...text: string[]) {
    text.forEach(t => this.pretty("primary", title, t));
  },

  success(title: string, ...text: string[]) {
    text.forEach(t => this.pretty("success", title, t));
  },

  warning(title: string, ...text: string[]) {
    text.forEach(t => this.pretty("warning", title, t));
  },

  danger(title: string, ...text: string[]) {
    text.forEach(t => this.pretty("danger", title, t));
  },

  info(title: string, ...text: string[]) {
    text.forEach(t => this.pretty("info", title, t));
  }
};

export { logger };
export default logger;
